package nc.ui.arap.pub;

import java.util.HashSet;
import java.util.Set;

import nc.ui.pub.bill.BillListPanel;
import nc.ui.pub.bill.BillModel;

public class BillListPanelTools {
	
	public static int[] getSelectedRows(BillListPanel listPanle) {
					
		int count = listPanle.getHeadBillModel().getDataVector().size();
		
		Set<Integer> selectedRowls = new HashSet<Integer>();
		for (int i = 0; i < count; i ++) {
			if (listPanle.getHeadBillModel().getRowState(i) == BillModel.SELECTED) {
				selectedRowls.add(i);
			} 
		}
		
		if (listPanle.getHeadTable().getSelectedRow() >= 0) {
			selectedRowls.add(listPanle.getHeadTable().getSelectedRow());
		}
		
		if (selectedRowls.isEmpty() && count != 0) selectedRowls.add(count - 1);
		int[] selectedRows = new int[selectedRowls.size()];
		int i = 0;
		for (Integer row : selectedRowls) {
			selectedRows[i ++] = row;
		}
		
		return selectedRows;
	}

}
